// import { dateFormat1 } from '@/basa/utils';

export default {
  data() {
    return {
      // approvaled审批通过  unapproval审批不通过  sendback审批退回 approving审批中
      labelType: {
        4: 'approvaled',
        5: 'unapproval',
        6: 'sendback',
        3: 'approving',
      },
      //清单名称
      paymentNames: '',
      // 审批状态
      approvalStatus: '',
      // 已经上传的附件数量
      attachmentUploadId: [],
      // 附件展示
      tableDataList: [],
      // 数据变动数据备份
      formCopyData: {},
      // 付款申请单号必填
      isRequired: true,
      // 新增 编辑 查看
      pageSatus: {
        add: '新增',
        look: '查看',
        edit: '编辑',
      },
    };
  },
  created() {
    this.initFun();
  },
  activated() {
    this.initFun();
  },
  computed: {
    /*  
    审批流程显示
    3审批中  4审批通过  5审批不通过 6审批退回
    */
    approvalStatusLook() {
      const arr = [3, 4, 5, 6];
      return arr.includes(this.approvalStatus) && this.editStatus === 'look';
    },
  },
  methods: {
    initFun() {
      //add-新增 look-查看 edit-编辑
      const { id, status } = JSON.parse(this.$route.params.id);
      this.approveId = id;
      // 可读可写控制
      if (status === 'edit' || status === 'look') {
        this.getLookDetailData(id);
        if (status === 'look') this.isDisabled = true;
      }

      // 保存状态
      this.editStatus = status;
    },
    // 处理时间格式
    dateFormatFun(formCopyData) {
      for (const keys in formCopyData) {
        if (
          keys === 'paymentTime' ||
          keys === 'reportTime' ||
          keys === 'registerTime' ||
          keys === 'createTime' ||
          keys === 'updateTime'
        ) {
          if (formCopyData[keys]) {
            //  formCopyData[keys] = dateFormat1(formCopyData[keys]);
            formCopyData[keys] = formCopyData[keys].split(' ')[0];
          }
        }
      }
    },

    //1-暂存
    submitHandleKeep() {
      this.formVerification(this.editStatus, 1);
    },

    // 保存并校验
    submitSaveCheck() {
      this.formVerification(this.editStatus, 2);
    },

    // 保存并提交
    submitHandle() {
      this.formVerification(this.editStatus, 3);
    },
    // 表单新增、编辑实时数据
    formCopyDataFun(formData) {
      this.formCopyData = {};
      this.formCopyData = formData;
    },

    // 附件上传成功数据
    attachmentSucessData(data) {
      console.log(data, '附件最新数据');
      this.attachmentUploadId = [];
      if (data.length > 0) {
        data.map((item) => {
          this.attachmentUploadId.push({
            uploadId: item.uploadId,
            fileExplain: item.fileExplain || '',
            createTime: item.createTime
          });
        });
      }
    },

    clearTableData(data) {
      this.$refs['tableList'].tableData = [];
      this.$refs['tableList'].copyData = [];
    },

    clearTable(params) {
      this.clearTableList = params;
    },

    getPconcId(params) {
      this.concId = params;
    },
  },
};
